#include <stdio.h>

int binarySearch(int *arrary, int item_nums, int goal)
{
    int right = 0;
    int left = item_nums - 1;
    int mid = 0;
    int conters = 0;

    if (item_nums == 1) {
        return 0;
    }
   
    while(right <= left) {
        mid = (right + left) / 2;
        conters++;
        if (arrary[mid] == goal) {
            printf("conters: %d\n", conters);
            return mid;
        } else if (arrary[mid] > goal) {
            left = mid - 1;
        } else {
            right = mid + 1;
        }
    }
    
}


int main()
{
    int arrary[] = {1, 2, 3, 4, 5, 6, 7, 8, 9, 10};
    int item_nums = sizeof(arrary) / sizeof(int);
    int goal = 9;
    int index = binarySearch(arrary, item_nums, goal);
    printf("index: %d\n", index);

    return 0;
}